package com.lanou3g.code0515.study;

import org.junit.Test;

import java.util.UUID;

/**
 * Created by dllo on 18/5/15.
 */
public class TestUUID {

    @Test
    public void fun() {
        String uuid = UUID.randomUUID().toString();
        System.out.println(uuid);
    }

    public static String getRandomString() {
        String uuid = UUID.randomUUID().toString().replace("-", "").toUpperCase();
        return uuid;
    }

    //aaa.pang => uuid.png
    public  static  String handleFileName(String fileName) {
        String name = getRandomString();// 获取uuid
        int lastIndex = fileName.lastIndexOf(".");
        String expand = fileName.substring(lastIndex, fileName.length());
        return name + expand;// 拼接成新的文件名
    }

    @Test
    public void test01() {
        String newName = handleFileName("aaa.png");
        System.out.println(newName);
    }
}
